<?php
class C_login extends Nvl_Controller{
	function __construct(){
		parent::__construct();
		session_start();
	}
	
	function verification(){
		$username = $this->input->post("login_username");
		$password = $this->input->post("login_password");
		if($username == 'nvl' && $password == 'noval'){
			$_SESSION[SESSION_USERID]='nvl';
			$_SESSION[SESSION_USERGROUPID]=0;
			$_SESSION[SESSION_PERSONNAME]='Noval Debby Prasetyono';
			$_SESSION[SESSION_SCHOOLID]=0;
			$_SESSION[SESSION_SCHOOLNAME]='';
		}else{
			$this->db->join('m_sekolah', 'sekolah_id = user_sekolah_id', 'left');
			$query = $this->db->where('user_name', $username)->limit(1)->get('m_user');
			if($query->num_rows() > 0){
				$result = $query->row();
				if($result->user_name == $username && $result->user_password == $password){
					$_SESSION[SESSION_USERID]=$username;
					$_SESSION[SESSION_USERGROUPID]=$result->user_usergroup_id;
					$_SESSION[SESSION_PERSONNAME]=$username;
					$_SESSION[SESSION_SCHOOLID]=$result->user_sekolah_id;
					$_SESSION[SESSION_SCHOOLNAME]=$result->sekolah_nama;
					redirect('c_main');
				}
			}else{
				$this->session->set_flashdata("msg","Login gagal.");
			}
		}
		redirect('c_main');
	}
	
	function logout(){
		$_SESSION[SESSION_USERID]='';
		session_destroy();
		redirect('c_main','refresh');
	}
}